/**
 * 获取产品详情
 * @param int id
 *
 */
export const getProductDetail = (id) =>
  uni.http({
    url: 'store/product/detail/' + id,
    method: 'get',
    noAuth: true,
    requestType: 'service',
  })
/**
 * 获取预览商品详情
 * @param int id
 *
 */
export function getPreviewProDetail(data) {
  return request.get('store/product/preview', data, {
    noAuth: true,
  })
}
/**
 * 产品分享二维码 推广员
 * @param int id
 */
export const getProductCode = (id, data) =>
  uni.http({
    url: 'store/product/qrcode/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 添加收藏
 * @param int id
 * @param string category product=普通产品,product_seckill=秒杀产品
 */
export const collectAdd = (data) =>
  uni.http({
    url: 'user/relation/create',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 删除收藏产品
 * @param int id
 * @param string category product=普通产品,product_seckill=秒杀产品
 */
export const collectDel = (data) =>
  uni.http({
    url: 'user/relation/delete',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 购车添加
 *
 */
export const postCartAdd = (data) =>
  uni.http({
    url: 'user/cart/create',
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })

/**
 * 获取分类列表
 *
 */
export const getCategoryList = () => {
  return uni.http({
    url: 'store/product/category/lst',
    method: 'GET',
    requestType: 'service',
    noAuth: true,
  })
}
/**
 * 获取产品列表
 * @param object data
 */

export function getProductslist(data) {
  if (data.brand_id && Array.isArray(data.brand_id)) {
    data = {
      ...data,
    }
    data.brand_id = data.brand_id.toString()
  }
  return uni.http({
    url: 'product/spu/lst',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
}
/**
 * 获取优惠券商品列表
 * @param object data
 */
export function getCouponProductlist(data) {
  if (data.brand_id && Array.isArray(data.brand_id)) {
    data = {
      ...data,
    }
    data.brand_id = data.brand_id.toString()
  }
  return request.get('product/spu/coupon_product', data, {
    noAuth: true,
  })
}
/**
 * 获取品牌列表
 * @param object data
 */
export const getBrandlist = (data) =>
  uni.http({
    url: 'store/product/brand/lst',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取推荐产品
 *
 */
export function getProductHot(page, limit) {
  return uni.http({
    url: 'product/spu/recommend',
    method: 'get',
    data: {
      page: page === undefined ? 1 : page,
      limit: limit === undefined ? 10 : limit,
    },
    requestType: 'service',
    noAuth: true,
  })
}
/**
 * 获取商户推荐产品
 *
 */
export function getMerProductHot(id, data) {
  return request.get(
    `product/spu/recommend`,
    {
      page: data.page === undefined ? 1 : data.page,
      limit: data.limit === undefined ? 10 : data.limit,
      mer_id: id || '',
    },
    {
      noAuth: true,
    },
  )
}
/**
 * 批量收藏
 *
 * @param object id
 * @param string category
 */
export function collectAll(data) {
  return request.post('user/relation/batch/create', data)
}
/**
 * 首页产品的轮播图和产品信息
 * @param int type
 *
 */
export function getGroomList(type, data) {
  return request.get('product/spu/hot/' + type, data, {
    noAuth: true,
  })
}
/**
 * 获取商品收藏列表
 * @param object data
 */
export function getCollectUserList(data) {
  return request.get('user/relation/product/lst', data)
}
/**
 * 获取商品收藏列表 -- 删除
 * @param object data
 */
export function userCollectDel(data) {
  return request.post('user/relation/batch/delete', data)
}
/**
 * 获取产品评论
 * @param int id
 * @param object data
 *
 */
export const getReplyList = (id, data) =>
  uni.http({
    url: 'store/product/reply/lst/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 产品评价数量和好评度
 * @param int id
 */
export function getReplyConfig(id) {
  return request.get('reply/config/' + id)
}
/**
 * 获取搜索关键字获取
 *
 */
export function getSearchKeyword() {
  return request.get(
    'common/hot_keyword',
    {},
    {
      noAuth: true,
    },
  )
}
/**
 * 门店列表
 * @returns {*}
 */
export function storeListApi(data) {
  return request.get('store_list', data, {
    noAuth: true,
  })
}
/**
 * 商户分类列表
 * @returns {*}
 */
export const storeMerchantCateList = (data) =>
  uni.http({
    // url: 'store/merchant/lst',
    url: 'intention/cate',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 商户列表
 * @returns {*}
 */
export const storeMerchantList = (data) =>
  uni.http({
    // url: 'store/merchant/lst',
    url: 'store/merchant/lst',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取商铺详情
 * @param {Object} id 商铺id
 * @param {Object} data 商铺数据
 */
export const getStoreDetail = (id, data) =>
  uni.http({
    url: 'store/merchant/detail/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 获取商铺商品列表
 * @param {Object} id 商铺 id
 * @param {Object} data 商铺商品列表数据
 */
export const getStoreGoods = (id, data) =>
  uni.http({
    url: 'product/spu/merchant/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取商铺分类列表
 * @param {Object} id 商铺 id
 * @param {Object} data
 */
export const getStoreCategory = (id, data) =>
  uni.http({
    url: 'store/merchant/category/lst/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 关注商铺
 * @param {Object} type_id 商铺 id
 */
export const followStore = (type_id) =>
  uni.http({
    url: 'user/relation/create',
    method: 'post',
    data: {
      type: 10,
      type_id: type_id,
    },
    requestType: 'service',
    noAuth: false,
  })
/**
 * 取消商铺关注
 * @param {Object} type_id 商铺 id
 */
export const unfollowStore = (type_id) =>
  uni.http({
    url: 'user/relation/delete',
    method: 'post',
    data: {
      type: 10,
      type_id: type_id,
    },
    requestType: 'service',
    noAuth: false,
  })
/**
 * 获取商铺优惠券
 * @param {Object} id
 */
export const getStoreCoupon = (id) =>
  uni.http({
    url: 'coupon/store/' + id,
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取平台优惠券
 * @param {Object} id
 */
export const getPlatFormCoupon = (id) =>
  uni.http({
    url: 'coupon/platform_lst/' + id,
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取商铺优惠券
 */
export function getMerchantLst(data) {
  return request.get('user/relation/merchant/lst', data, {
    noAuth: true,
  })
}
/**
 * 物流信息
 */
export function express(id) {
  return request.post('ordero/express/' + id, {
    noAuth: true,
  })
}
/**
 * 子集分类
 * @returns {*}
 */
export function storeCategory(pid) {
  return request.get('store/product/category', pid, {
    noAuth: true,
  })
}
/**
 * 分销说明
 * @returns {*}
 */
export function bagExplain() {
  return request.get('store/product/bag/explain')
}
/**
 * 分销礼包推荐列表
 * @returns {*}
 */
export function bagRecommend() {
  return request.get('product/spu/bag/recommend')
}
/**
 * 分销礼包列表
 * @returns {*}
 */
export function productBag(data) {
  return request.get('product/spu/bag', data, {
    noAuth: true,
  })
}
/**
 * 商铺二维码
 * @returns {*}
 */
export const merchantQrcode = (id, data) =>
  uni.http({
    url: 'store/merchant/qrcode/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 推荐商品
 * @returns {*}
 */
export function merchantProduct(id, data) {
  if (data.brand_id && Array.isArray(data.brand_id)) {
    data = {
      ...data,
    }
    data.brand_id = data.brand_id.toString()
  }
  return uni.http({
    url: 'product/spu/merchant/' + id,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
}
/**
 * 推荐商品banner
 * @returns {*}
 */
export function getHotBanner(type) {
  return request.get(
    'common/hot_banner/' + type,
    {},
    {
      noAuth: true,
    },
  )
}
/**
 * 商户入驻表单
 * @returns {*}
 */
export function create(data) {
  return request.post('intention/create', data)
}
/**
 * 商户入驻短信验证码
 * @returns {*}
 */
export function verify(data) {
  return request.post('auth/verify', data)
}
/**
 * 获取秒杀商品详情
 * @param int id
 *
 */
export function getSeckillProductDetail(id) {
  return uni.http({
    url: 'store/product/seckill/detail/' + id,
    method: 'get',
    requestType: 'service',
    noAuth: false,
  })
}
/**
 * 直播推荐列表
 * @returns {*}
 */
export const getLiveList = (data) =>
  uni.http({
    url: 'broadcast/hot',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 直播列表
 * @returns {*}
 */
export function getBroadcastListApi(data) {
  return request.get('broadcast/lst', data, {
    noAuth: true,
  })
}
/**
 * 商户分类
 * @returns {*}
 */
export const merClassifly = () =>
  uni.http({
    url: 'intention/cate',
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取预售商品详情
 * @param int id
 *
 */
export function getPresellProductDetail(id) {
  return request.get(
    'store/product/presell/detail/' + id,
    {},
    {
      noAuth: true,
    },
  )
}
/**
 * 获取商户申请记录
 * @param int id
 *
 */
export function getApplicationRecordList(data) {
  return request.get('intention/lst', data)
}
/**
 * 获取商户申请详情
 * @param int id
 *
 */
export function getGoodsDetails(id) {
  return request.get('intention/detail/' + id, {})
}

/**
 * 修改入驻信息
 * @param int id
 *
 */
export function updateGoodsRecord(id, data) {
  return request.post('intention/update/' + id, data)
}
/**
 * 获取定位详细地址
 * @param int id
 *
 */
export const getGeocoder = (data) =>
  uni.http({
    url: `lbs/geocoder?location=${data.lat},${data.long}`,
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/**
 * 获取店铺类型
 * @param int id
 *
 */
export const getStoreTypeApi = () =>
  uni.http({
    url: 'intention/type',
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/**
 * 到货通知
 *
 */
export function arrivalNoticeApi(data) {
  return uni.http({
    url: 'store/product/increase_take',
    method: 'post',
    data,
    requestType: 'service',
  })
}

/*
  获取图片验证码
*/
export const getCaptcha = () =>
  uni.http({
    url: 'captcha',
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
/*
  获取店铺资质
*/
export const storeCertificate = (data) =>
  uni.http({
    url: `store/certificate/${data.merId}`,
    method: 'post',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 本地服务列表
 * @returns {*}
 */
export const storeServiceList = (id, data) =>
  uni.http({
    url: `product/spu/local/${id}`,
    method: 'get',
    data,
    requestType: 'service',
    noAuth: true,
  })
/**
 * 复制口令
 * @returns {*}
 */
export const copyPasswordApi = (data) =>
  uni.http({
    url: 'product/spu/copy',
    method: 'get',
    data,
    requestType: 'service',
    noAuth: false,
  })
/**
 * 口令搜索
 * @returns {*}
 */
export function copyPasswordSearch(data) {
  return request.get(`command/copy`, data, {
    noAuth: true,
  })
}
/**
 * 套餐列表
 * @returns {*}
 */
export function getDiscountsLst(data) {
  return request.get(`discounts/lst`, data, {
    noAuth: true,
  })
}
/**
 * 套餐--立即购买
 * @returns {*}
 */
export function discountsCartAdd(data) {
  return request.post('user/cart/batchCreate', data)
}
/**
 * 商品--价格说明
 * @returns {*}
 */
export const priceRuleApi = (id) =>
  uni.http({
    url: `store/product/price_rule/${id}`,
    method: 'get',
    requestType: 'service',
    noAuth: true,
  })
